package fr.pud.client.controller.routes;

import javax.swing.JCheckBox;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import fr.pud.client.view.JMapViewerExtended;
import fr.pud.client.view.MapRoutes;

/**
 * Apr 14, 2012 - Projet_Ose.
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         DisplayOrHideAMapRoute.java
 */
public class DisplayOrHideAMapRoute implements ChangeListener {
    @Override
    public void stateChanged(ChangeEvent aE) {
        if (aE.getSource() instanceof JCheckBox) {
            JCheckBox check = (JCheckBox) aE.getSource();
            if (check.isSelected()) {
                MapRoutes.getInstance().getRoutes()
                        .get(Integer.parseInt(check.getText()))
                        .setVisible(false);
                JMapViewerExtended.getJMapViewer().repaint();
            }
            else {
                MapRoutes.getInstance().getRoutes()
                        .get(Integer.parseInt(check.getText()))
                        .setVisible(true);
                JMapViewerExtended.getJMapViewer().repaint();
            }
        }
    }
}
